import {
  getUserAll,
  getUsersArr,
  SearchUserKey,
  updataUserById,
  deleteUserById,
  deleteUserMoreById,
  SelectMybyId,
  upUserImg,
  updataBaseUserById,
  updataEcxUserById,
} from "../../api/user.js";
import { verifyToken } from "../../utils/TokenCheck.js";
import { upload, createUploader } from "../../FileSystem/image-processor.js";

export default function userRouter(router) {
  // 获取全部用户信息
  router.get("/getUserAll", verifyToken, getUserAll);
  // 分页查询用户信息
  router.post("/getUserPage", verifyToken, getUsersArr);
  // 根据key-value分页查询指定用户信息
  router.post("/SearchUserKey", verifyToken, SearchUserKey);
  // 修改指定id用户信息
  router.post("/updataUserById", verifyToken, updataUserById);
  // 删除指定id用户信息
  router.delete("/deleteUserById/:id", verifyToken, deleteUserById);
  // 批量删除指定id用户信息
  router.post("/deleteUserMoreById", verifyToken, deleteUserMoreById);
  // 联表查询指定id用户信息
  router.get("/searchMybyId/:id", verifyToken, SelectMybyId);
  // 用户头像上传
  router.post(
    "/upload/avatar",
    verifyToken,
    createUploader({
      baseDir: "uploads/avatars",
      //  自定义命名器
      filenameGenerator: (req, file, ext) => {
        const userId = req.headers["x-user-id"];
        return `${userId}${ext}`;
      },
    }).single("file"),
    upUserImg
  );  
  // 修改指定id用户基本信息
  router.post("/updataBaseUserById", verifyToken, updataBaseUserById);
  // 修改指定id用户职业经历
  router.post("/updataEcxUserById", verifyToken, updataEcxUserById);
}
